﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Xml;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApp.ProductService;
using WebApp.DomainService;
using WebApp.CompanyService;
using WebApp.TypeService;

namespace WebApp
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        ProductServiceClient ProductClient;
        protected void Page_Load(object sender, EventArgs e)
        {
            ProductClient = new ProductServiceClient();
            WriteXMLToFile();
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("App_Data/HocSinh.xml"));
            dlQuangCao.DataSourceID = null;
            dlQuangCao.DataSource = ds;
            dlQuangCao.DataBind();
            
        }
        
      public DataTable GetDSHocSinh()
        {
            DataTable dtb = new DataTable();
            //Tạo các Columns
            dtb.Columns.Add("HoTen");
            dtb.Columns.Add("Lop");
            dtb.Columns.Add("Toan");
            dtb.Columns.Add("Ly");
            dtb.Columns.Add("Hoa");
            dtb.Columns.Add("NgoaiNgu");
            //Thêm các bản ghi
            dtb.Rows.Add("Bùi Anh Khoa", "A3", "10", "9", "8", "7");
            dtb.Rows.Add("Nguyễn Mạnh Hùng", "A3", "7", "8", "9", "10");
            dtb.Rows.Add("Hoàng Đức Hải", "A3", "6", "7", "8", "9");
            dtb.Rows.Add("Bùi Vãi Trưởng", "A3", "5", "6", "8", "7");
            dtb.Rows.Add("Bùi Học Rốt", "A3", "4", "5", "6", "7");
            dtb.Rows.Add("Bùi van a", "A3", "4", "5", "6", "7");
            return dtb;
        }
        private void WriteXMLToFile()
        {
            XmlTextWriter xmlwriter = new XmlTextWriter(Server.MapPath("App_Data/HocSinh.xml"), Encoding.UTF8);
            xmlwriter.Formatting = Formatting.Indented;
            xmlwriter.WriteStartDocument();
            xmlwriter.WriteComment("hmweb.com.vn Ghi dữ liệu ra XML");
            xmlwriter.WriteStartElement("HocSinh");
            DataTable dt = GetDSHocSinh();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                xmlwriter.WriteStartElement("HocSinh");
                xmlwriter.WriteAttributeString("HoTen", dt.Rows[i]["HoTen"].ToString());
                xmlwriter.WriteElementString("Lop", dt.Rows[i]["Lop"].ToString());
                xmlwriter.WriteElementString("Toan", dt.Rows[i]["Toan"].ToString());
                xmlwriter.WriteElementString("Ly", dt.Rows[i]["Ly"].ToString());
                xmlwriter.WriteElementString("Hoa", dt.Rows[i]["Hoa"].ToString());
                xmlwriter.WriteElementString("NgoaiNgu", dt.Rows[i]["NgoaiNgu"].ToString());
                xmlwriter.WriteEndElement();
            }
            xmlwriter.WriteEndElement();
            xmlwriter.WriteEndDocument();
            xmlwriter.Flush();
            xmlwriter.Close();
        }
       /* private List<ProductDTO> GetAllProduct()
        {
            List<ProductDTO> newlist = new List<ProductDTO>();
            newlist.AddRange(ProductClient.GetAllProducts());
            return newlist;

        }

        private void WriteXMLToFile()
        {
            XmlTextWriter xmlwriter = new XmlTextWriter(Server.MapPath("App_Data/HocSinh.xml"), Encoding.UTF8);
            xmlwriter.Formatting = Formatting.Indented;
            xmlwriter.WriteStartDocument();
            xmlwriter.WriteComment("hmweb.com.vn Ghi dữ liệu ra XML");
            xmlwriter.WriteStartElement("SanPham");

            ////Duyet tat ca san pham
            List<ProductDTO> newlist = GetAllProduct();
            foreach (ProductDTO item in newlist)
            {
                xmlwriter.WriteStartElement("SanPham");
                xmlwriter.WriteAttributeString("TenSanPham", item.ProductName);
                xmlwriter.WriteElementString("Image", item.Image);
                xmlwriter.WriteElementString("Gia", item.Price.ToString());
                xmlwriter.WriteElementString("GiaKM", item.ProPrice.ToString());
                xmlwriter.WriteEndElement();
            }

           

            xmlwriter.WriteEndElement();
            xmlwriter.WriteEndDocument();
            xmlwriter.Flush();
            xmlwriter.Close();
        }*/
    }
    
}